package com.c8a.validation.controller;

import com.c8a.validation.entity.Employee;
import com.c8a.validation.entity.StudentVO;
import com.c8a.validation.utils.ValidUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;

/**
 * ValidUtils工具类校验
 *
 * @Author C8A
 * @Date 2022-04-24 16:44
 * @Email 1912327276@qq.com
 */

@RestController
public class ValidUtilsController {

    /**
     *
     * {
     *     "students": [
     *         {
     *             "id": 1,
     *             "name": "weqd",
     *             "title": "初级开发工程师",
     *             "age": 22,
     *             "email": "23123@qq.com"
     *         },
     *         {
     *             "id": 2,
     *             "name": "jack",
     *             "title": "初级顾问",
     *             "age": 16,
     *             "email": "2311123@qq.com"
     *         }
     *     ]
     * }
     * @param studentVO
     * @return
     */
    @PostMapping("/valid7")
    public ResponseEntity<StudentVO> valid7(@RequestBody StudentVO studentVO) {
        ValidUtils.valid(studentVO);
        return ResponseEntity.ok(studentVO);
    }

    /**
     *{
     *     "id": 1,
     *     "name": "Query",
     *     "studentVO": {
     *         "students7": [
     *             {
     *                 "id": 1,
     *                 "name": "eddie",
     *                 "title": "初级开发工程师",
     *                 "age": 22,
     *                 "email": "23123@qq.com"
     *             },
     *             {
     *                 "id": 2,
     *                 "name": "jack",
     *                 "title": "初级顾问",
     *                 "age": 26,
     *                 "email": "231223@qq.com"
     *             }
     *         ]
     *     }
     * }
     * @param employee
     * @return
     */
    @PostMapping("/valid8")
    public ResponseEntity<Employee> valid8(@RequestBody Employee employee) {
        ValidUtils.valid(employee,Employee.Query.class, Default.class);
        return ResponseEntity.ok(employee);
    }

}
